package com.lry.crawlers.video.service.impl;

import com.lry.crawlers.util.ProcessVariable;
import com.lry.crawlers.video.entity.VideoVariable;
import com.lry.crawlers.video.mapper.VideoVariableMapper;
import com.lry.crawlers.video.service.VideoVariableService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.List;

@Service
public class VideoVariableServiceImpl implements VideoVariableService {
    @Autowired
    VideoVariableMapper videoVariableMapper;
    //初始化FictionVariable信息
    @PostConstruct
    private void initialize() {
        List<VideoVariable> videoVariables = getVideoVariables();
        for (VideoVariable v: videoVariables){
            ProcessVariable.setVVariable(v.getId(),v);
        }

    }

    public void update(){
        initialize();
    }

    @Override
    public int setVideoVariable(VideoVariable videoVariable) {
        int insert = videoVariableMapper.insert(videoVariable);
        return insert;
    }

    @Override
    public List<VideoVariable> getVideoVariables() {
        return videoVariableMapper.selectList(null);
    }

}
